Java 8 New Features by Richard Reese

Java 8 New Features by Richard Reese
Author: Richard Reese [Reese, Richard]
Language: eng
Format: epub
Tags: Computers and Internet: Java
Publisher: P8tech
Published: 2014-07-14

Below, a stream is created based on the partsList and is used with a combination of predicate lambda expressions. While the example seems to execute these methods one after another, remember that a stream cannot be reused. To make this example work, the stream has to be recreated before each execution of a match method.

Stream<Part> partsStream = partsList.stream();

System.out.println(partsStream.

allMatch(p -> p.getQuantity()<50));

System.out.println(partsStream.

anyMatch(p -> p.getQuantity()<50));

System.out.println(partsStream.

noneMatch(p -> p.getQuantity()<50));

System.out.println(partsStream.

allMatch(p -> p.getWeight()>50));

System.out.println(partsStream.

anyMatch(p -> p.getQuantity()>1000));

System.out.println(partsStream.

noneMatch(p -> p.getPrice()>.35f));